package com.codecash.mapper;

import com.codecash.entity.FeedBack;
import com.codecash.entity.User;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserMapper {
    @Select("select * from users where username =#{username}")
    //根据用户名查询用户
    User findByUserName(String username);
    //添加
    @Insert("insert into users (username,password,email,create_time,update_time)" +
            "values(#{username},#{password},#{email},now(),now())")
    void add(String username, String password,String email);
    // 仅更新 username 和 email
    @Update("UPDATE users SET username = #{username}, email = #{email}, update_time = NOW() WHERE id = #{id}")
    void updatePartial(@Param("username") String username, @Param("email") String email, @Param("id") Integer id);

    // 检查用户名唯一性
    @Select("SELECT COUNT(*) FROM users WHERE username = #{username} AND id != #{userId}")
    int countByUsername(@Param("username") String username, @Param("userId") Integer userId);


    @Update("update users set avatar_url =#{avatarUrl},update_time=now() where id =#{id}")
    void updateAvatar(String avatarUrl,Integer id);

    @Update("update users set password = #{md5String},update_time=now() where id =#{id}")
    void updatePwd(String md5String, Integer id);
    @Select("select * from users where email =#{email}")
    User findByEmail(String email);

    //用户反馈
    @Insert("insert into user_feedback (user_id, content, create_time) " +
            "values(#{userId}, #{content}, #{createTime})")
    void addCall(FeedBack feedBack);
}
